from django.shortcuts import render
from .models import ContentCategory
from goods.models import GoodsCategory,GoodsChannel
from django.conf import settings
from goods.utils import get_categories

def generic_index_html():

    categories = get_categories()
    contents = {}
    content_categories = ContentCategory.objects.all()
    for content_category in content_categories:
        contents[content_category.key] = content_category.contents.filter(status=True).order_by('sequence')
    #1.2广告
    context={
        'categories':categories,
        'contents':contents,
    }


    #2.生成html
    response = render(None,'index.html',context)
    html_str = response.content.decode()
    #3.写文件
    with open(settings.GENERATE_STATIC_HTML_FILE_DIR+'index.html',mode='w') as f:
        f.write(html_str)